import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { failHandler, getPkgInfo } from "@/common";
import { getCommand } from "./base";
import _curry from "lodash.curry";

const { version } = getPkgInfo();

export const createCli = () => {
  const argv = hideBin(process.argv);
  const cli = yargs(argv);

  return cli
    .strict()
    .version(version)
    .alias("h", "help")
    .alias("v", "version")
    .recommendCommands()
    .demandCommand(1)
    .command(
      getCommand({
        command: "add",
        describe: "创建组件",
      }),
    )
    .command(
      getCommand({
        command: "remove",
        describe: "移除组件",
      }),
    )
    .usage("Usage: $0 <command>")
    .help("help")
    .fail(_curry(failHandler)("PARENT_CMD")).argv;
};
